<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>学生信息 - 添加学生信息</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/static/admin/layui/css/layui.css" rel="stylesheet">
    <link rel="shortcut icon" href="../set/favicon.ico"> <link href="/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    
    <link href="/static/admin/css/animate.css" rel="stylesheet">
    <link href="/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="/static/admin/layui/layui.js"></script>
    
    <script type="text/javascript">
        layui.config({
            base: '/static/admin/layui/lay/modules/'
        }).extend({
            excel: 'excel.min'
        });
    </script>
    <script src="/static/admin/js/excel-import.js"></script>
    <style>
        .label-danger{
            display: none;
        }
        .reResInfoBox{
            margin: 70px 20px 0px 20px;
            display : none;
        }
        .layui-tab-title{
            border-color: #e6e6e6;
        }
        .layui-tab-title .layui-this:after{
            border-color: #e6e6e6;
            border-bottom-color: #fff;
        }
        .form-control, .single-line{
            padding: 0px 12px;
        }
        .zyc {
             /* display: none; */
             margin: 10px 10px;
         }
         .zyc input{
            width: 130px;
            height: 100%;
            display: inline-block;
            font-weight: bold;
            text-align: center;
            letter-spacing: 0.3em;
         }
         .zyc textarea{
            border-color: #cfdadd;
            border-radius: 2px;
         }
         .zyc img{
            display: inline-block;
            width: 100px;
            margin-top: -4px;
            border-radius: 2px;
            border: 1px #cfdadd solid;
         }
         .zyc select {
            padding: 0px 12px;
         }
         #zycsubmit{
            display: block;
            margin-top: 10px;
            border-radius: 2px;
         }
    </style>

</head>

<body class="gray-bg">
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <h2>录入学生信息</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="{:url('Student/add')}">主页</a>
                </li>
                <li>
                    <strong>添加学生信息</strong>
                </li>
            </ol>
        </div>
    </div>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
             <div class="col-sm-14">
             
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>录入学生信息</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal" >
                         
                           <div class="form-group">
                                <label class="col-sm-2 control-label">学生姓名：</label>
                                <div class="col-sm-4">
                                    <input type="text"  placeholder="请输入学生名" id="username" value="" class="form-control">
                                </div>
                                <span class="label label-danger">姓名格式错误，请输入学生中文姓名</span>
                                <div class='col-sm-6'></div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">手机号码：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入电话" id="phone"  value="" class="form-control">
                                </div>
                                <span class="label label-danger">手机号码格式错误</span>
                                <div class='col-sm-6'></div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">微信：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入微信" id="wechat"  value="" class="form-control">
                                </div>
                                <span class="label label-danger">请填写手机号或微信号中的一个</span>
                                <div class='col-sm-6'></div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">咨询形式：</label>
                                <div class="col-sm-4">
                                    <select id="zx_form" name="zx_form" class="form-control">
                                        <option value="">-请选择-</option>
                                        <option value="来电">来电</option>
                                        <option value="来访">来访</option>
                                        <option value="网络">网络</option>
                                        <option value="老学员介绍">老学员介绍</option>
                                        <option value="其他">其他</option>
                                    </select>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">信息来源：</label>
                                <div class="col-sm-4">
                                    <select  id="infosource"  value="" class="form-control">
                                        <option value="" selected>-请选择-</option>
                                        <option value="网络搜索">网络搜索</option>
                                        <option value="网代介绍">网代介绍</option>
                                        <option value="朋友介绍">朋友介绍</option>
                                        <option value="内部转介">内部转介</option>
                                        <option value="报纸广告">报纸广告</option>
                                        <option value="展会活动">展会活动</option>
                                        <option value="地推传单">地推传单</option>
                                        <option value="在线客服">在线客服</option>
                                        <option value="渠道合作">渠道合作</option>
                                        <option value="室外广告">室外广告</option>
                                        <option value="校园宣传">校园宣传</option>
                                        <option value="项目渠道">项目渠道</option>
                                        <option value="雅思考点">雅思考点</option>
                                        <option value="托福考点">托福考点</option>
                                        <option value="线上推广">线上推广</option>
                                        <option value="其他">其他</option>
                                    </select>
                                </div>
                                <span class="label label-danger">来源格式错误</span>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                    <label class="col-sm-2 control-label">来源明细：</label>
                                    <div class="col-sm-4">
                                        <input type="text" placeholder="来源明细" id="source_details"  value="" class="form-control">
                                    </div>
                                    <span class="label label-danger">来源明细</span>
                                    <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">咨询课程：</label>
                                <div class="col-sm-4">
                                    <select id="zx_course" name="zx_course" class="form-control">
                                        <option value="">-请选择-</option>
                                        {foreach $zx_course_select as $zx_course}
                                        <option value="{$zx_course['name']}">{$zx_course['name']}</option>
                                        {/foreach}
                                    </select>
                                </div>
                                <span class="label label-danger">来源明细</span>
                                <div class='col-sm-6'></div>
                        </div>
                            <div class="form-group">
                                    <label class="col-sm-2 control-label">下次回访时间：</label>
                                    <div class="col-sm-4">
                                        <input type="text" placeholder="来源明细" id="returnvisit_time" readonly value="" class="form-control">
                                    </div>
                                    <span class="label label-danger">下次回访时间</span>
                                    <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">接待员工：</label>
                                <div class="col-sm-4">
                                    <select  class="form-control" id="receptionist" name="receptionist">
                                        <option value="-1">--未选中--</option>
                                        {volist name='receptionist' id='vo'}
                                            <option value="{$vo.id}">{$vo.username}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <span class="label label-danger">请选择接待员</span>
                                
                            </div>

                            <div class="form-group">
                                    <input type="radio"  name="sstatus" checked='checked' id="status" value="3" style="display:none;">
                            </div>
                            <div class='col-sm-6'></div>
                            </div>

                            <div class="form-group" style="overflow: hidden;">
                                <div class="col-sm-offset-2 col-sm-6">
                                    <input type="button"  value="保 存"  class="btn btn-sm btn-info" id="adds" />
                                    <input type="button"  value="excel导入"  class="btn btn-sm btn-info" id="excelbtn" />

                                    <input type="file" class="layui-btn" style="display: none;" id="LAY-excel-import-excel" multiple="multiple">
                                </div>
                       
                            </div>
                        </form>
                        
                        
                            <div class="reResInfoBox">
                                <h3 style="text-align: center;color: #a2a2a2;" >发现以下重复信息</h3>
                                    <table class="layui-table">
                                            <colgroup>
                                            <col width="150">
                                            <col width="200">
                                            <col width="200">
                                            <col>
                                            </colgroup>
                                            <thead>
                                            <tr>
                                                <th>学生姓名</th>
                                                <th>学生状态</th>
                                                <th>学生分类</th>
                                                <th>地址</th>
                                                <th>来源</th>
                                                <th>咨询顾问</th>
                                                <th>接待员</th>
                                                <th>录入时间</th>
                                                <th>咨询记录</th>
                                            </tr> 
                                            </thead>
                                            <tbody class="reResInfo">
                                                <tr>
                                                    <td class="sname"></td>
                                                    <td class="sstatus"></td>
                                                    <td class="student_class"></td>
                                                    <td class="sadd"></td>
                                                    <td class="infosource"></td>
                                                    <td class="consultant"></td>
                                                    <td class="receptionist"></td>
                                                    <td class="create_time"></td>
                                                    <td class="sid"></td>
                                                </tr>
                                            </tbody>
                                    </table>
                            </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/admin/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="/static/admin/js/content.js?v=1.0.0"></script>
    
    <script>
        var excelAddUrl = "{:url('Student/exceladd')}"
        layui.use(['layer','laydate','upload'], function(){ //独立版的layer无需执行这一句
            var $ = layui.jquery,
            layer = layui.layer,
            upload = layui.upload,
            laydate = layui.laydate,
            photo=''; //独立版的layer无需执行这一句

            laydate.render({  //下次回访时间

                
                elem    : '#returnvisit_time', 
                event   : 'focus' ,  //获得焦点是触发
            });

            //点击查看日志
            $(".reResInfoBox").on('click','.viewlog',function(){
                var id = $(this).attr('data-id');
                var url = "{:url('Logsystem/index')}?id="+id;
                layer.open({
                title: '日志',
                type: 2, 
                area: ['800px', '600px'],
                content: url
                }); 
            });

            //点击提交
            $("#adds").click(function(){
                if(!checkForm()) return false;

                var status=$("input[type='radio']:checked").val();
    
                $.post("{:url('Student/add')}",{
                    sstatus     : status,//资源默认状态
                    zxr_tel     : $("#phone").val(),//咨询人电话
                    wechatqq     : $("#wechat").val(),//咨询人微信
                    zx_form     : $("#zx_form").val(),//咨询形式
                    zx_course	: $("#zx_course").val(),//咨询课程
                    sname       : $("#username").val(), //学生姓名
                    infosource  : $("#infosource").val(),//数据来源
                    receptionist: $("#receptionist").val(),//接待员
                    source_details: $("#source_details").val(),//来源明细
                    returnvisit_time: $("#returnvisit_time").val(),    //下次回访时间
                },function(msg){
                        
                        if (msg.code==1) {
                            layer.msg('录入信息成功',{time:2000},function(){
                                window.location.reload();
                            });
                        }else if(msg.code==0){
                            layer.msg(msg.msg,{time:2000});
                            var data = msg.data;

                            $('.reResInfoBox').css('display','block');
                            $(".reResInfo tr").children('td').each(function(){
                                var classname = $(this).attr('class');
                                $(this).html(data[0][classname]);
                            });

                            return false;
                        }
                        
                           
                       
                });
            });

            
            $('#excelbtn').click(function () {
                    $('#LAY-excel-import-excel').trigger('click');
            });

            //显示重复资源
            function showReResInfoBox(msg) {
                if (msg != 0) {
                    $('.reResInfoBox').css('display', 'block');
                    $(".reResInfo tr").children('td').each(function () {
                        var classname = $(this).attr('class');
                        if (classname == 'sid') {
                            $(this).html('<a href="javascript:;" class="viewlog" data-id="' + msg[0][classname] + '">咨询记录</a>');
                        } else {
                            $(this).html(msg[0][classname]);
                        }
                    });
                } else {
                    $('.reResInfoBox').css('display', 'none');
                    $(".reResInfo tr").children('td').each(function () {
                        var classname = $(this).attr('class');
                        $(this).html('');
                    });
                }
            }


            $("#phone").on('blur',function(){  //当手机号输入框失去焦点时 查询重复信息
                var phone = $(this).val();
                $.get("{:url('Student/searchRes')}",{type:'zxr_tel',value:phone},function(msg){
                    showReResInfoBox(msg)
                });
            });
            $("#wechat").on('blur',function(){  //当微信号输入框失去焦点时 查询重复信息
                var wechat = $(this).val();
                $.get("{:url('Student/searchRes')}",{type:'wechatqq',value:wechat},function(msg){
                    showReResInfoBox(msg)
                });
            });

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                ,url: "{:url('Admins/upload')}"
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code == 0){
                        return layer.msg('上传失败');
                    }else if(res.code){
                        //上传成功
                        photo = res.photo;
                        return layer.msg('上传成功');
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });

        //验证表单
        function checkForm(){
            var phone = $("#phone").val();
            var username = $("#username").val();
            var receptionist = $("#receptionist").val();//接待员
            var wechat = $("#wechat").val();//微信
            
            var ismobile = strCheck.mobile(phone); //判断手机号格式是否正确
            var ischinese = strCheck.chinese(username); //判断是否是中文
            var isreceptionist = receptionist>=0?true:false; //判断

            if(phone == ''){
                if (wechat == '') {
                    $("#wechat").parent('div').siblings('.label-danger').css("display","inline-block");
                    return false;
                } else {
                    return true;
                }

            }

            $(".form-group .label-danger").css("display","none"); //将错误提示全部关闭
            //判断是否全部验证通过,不通过给予提示
            if(ismobile&&ischinese&&isreceptionist){
                //通过所有验证
                return true;
            }else{
                //未通过验证
                if (!ismobile)  $("#phone").parent('div').siblings('.label-danger').css("display","inline-block");
                if (!ischinese) $("#username").parent('div').nextAll('.label-danger').css("display","inline-block");
                if (!isreceptionist) $("#receptionist").parent('div').nextAll('.label-danger').css("display","inline-block");

                return false;
            }
        }

    </script>
    
    

    <script type="text/html" id="LAY-excel-export-ans">

            
            <div class="layui-tab">
              <ul class="layui-tab-title">
                    <li class="layui-this">{{d.tab}}</li>
                    
              </ul>
              <select  class="form-control" id='receptionist2' style='display:inline-block'>
                    <option value="-1">--选择接待员--</option>
                    {volist name='receptionist' id='vo'}
                        <option value="{$vo.id}">{$vo.username}</option>
                    {/volist}
              </select>
              <div class="">
                    <div class="layui-tab-item layui-show">
                            <table class="layui-table excel-import-datalist" >
                                {{# layui.each(d.data, function(index, value) { }}
                                    <tr>
                                        {{# layui.each(value, function(key, val) { }}
                                        <td>{{val}}</td>
                                        {{# });}}
                                    </tr>
                                {{# });}}
                            </table>
                           
                        </div>
                 
              </div>
            </div>
       
        
    </script>

</body>

</html>
